package com.syni.mdd.yhd.common.all.quartz.activity;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsDxClientRole;
import com.syni.mdd.yhd.common.all.entity.BmsDxOrder;
import com.syni.mdd.yhd.common.all.entity.activity.BmsUserOverMeal;
import com.syni.mdd.yhd.common.all.entity.activity.CountBussinessActivity;
import com.syni.mdd.yhd.common.all.entity.activity.CountUserActivity;
import com.syni.mdd.yhd.common.all.entity.coupon.BmsUserReceCoupon;
import com.syni.mdd.yhd.common.all.entity.user.BmsUser;
import com.syni.mdd.yhd.common.all.service.*;
import com.syni.mdd.yhd.common.all.service.activity.OverMealService;
import com.syni.mdd.yhd.common.all.service.record.CountBussinessActivityService;
import com.syni.mdd.yhd.common.all.service.record.CountUserActivityService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ArithUtil;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.yhd.common.all.utils.SpecificationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @className BmsVideoQuartz
 * @description TOO
 * @Author cfx
 * @DATE 2019/7/26 16:15
 * @VERSION 1.0
 **/
@Component
@EnableScheduling
public class MealOverQuartz {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    CountBussinessActivityService countBussinessActivityService;

    @Autowired
    CountUserActivityService countUserActivityService;

    @Autowired
    BmsUserReceCouponService bmsUserReceCouponService;

    @Autowired
    BmsBusinessService bmsBusinessService;

    @Autowired
    BmsUserService bmsUserService;

    @Autowired
    BmsDxClientRoleService bmsDxClientRoleService;

    @Autowired
    BmsDxOrderService bmsDxOrderService;

    @Autowired
    OverMealService overMealService;

    //@Scheduled(cron = "0 0 0 * * ?")  //每天晚上凌晨执行一次定时任务
    //@Scheduled(cron = "0/5 * * * * ?")
    public void mealOverQuartz() {
        //重置当天抽奖次数
        Map<String,Object> conditionMap = new HashMap<>();
        conditionMap.put("haveNum_GTT",Constants.COMMON_FLAG_FALSE_INT);
        List<BmsUserOverMeal> bmsUserOverMeals = overMealService.getBaseDao().findAll(new SpecificationUtils(conditionMap));
        if(bmsUserOverMeals != null && bmsUserOverMeals.size() > 0){
            for(BmsUserOverMeal bmsUserOverMeal : bmsUserOverMeals){
                bmsUserOverMeal.setTodayNum(1);
            }
            overMealService.getBaseDao().saveAll(bmsUserOverMeals);
        }
    }
}
